public class Test_Opportunity_Clone {
	static testMethod void testCloneOpp(){
	//create a contact
	Contact firstContact = new Contact (
		FirstName='Joe',
		LastName='Johanssen',
		MailingStreet='123 Elm St',
		MailingCity='Wauwatosa',
		MailingState='WI',
		MailingPostalCode='53213',
		MailingCountry='USA'			
	);
	insert firstContact;
	
	//create a gift
	Opportunity opp1 = new Opportunity (
		Name='Joe Johanssen 2005 Gift',
		CloseDate=Date.newInstance(2005,10,10),
		StageName='Closed Won',
		Amount=100	
	);
	insert opp1;
	//create a contact role for that gift and contact
	OpportunityContactRole cr1 = new OpportunityContactRole (
		OpportunityId=opp1.id,
		ContactId=firstContact.id,
		Role='Individual Donor',
		IsPrimary=true						
	);
	insert cr1;
	
	Id NewOppId;
	NewOppId = OpportunityWebServices.cloneOpp(opp1.id,1,'Year');
	
	Opportunity[] ClonedOpp = [select Name, StageName, CloseDate from Opportunity where Id =:NewOppId];
	//new opp should be created with correct name
	System.assertEquals('Joe Johanssen 2006 Gift',ClonedOpp[0].Name);
	System.assertEquals('Prospecting',ClonedOpp[0].StageName); 
	System.assertEquals(opp1.CloseDate.addYears(1),ClonedOpp[0].CloseDate); 
	
	//MP: test contact role. 1. correct contact 2. correct role of correct contact
	OpportunityContactRole primaryContactRole = [select ContactId, Contact.FirstName, Contact.LastName, Role, IsPrimary from OpportunityContactRole where OpportunityId = :NewOppId and IsPrimary=true];
	System.assertEquals(firstContact.id, primaryContactRole.ContactId);
	System.assertEquals('Individual Donor', primaryContactRole.Role);	
	
	//clone the opp again one month out
	NewOppId = OpportunityWebServices.cloneOpp(opp1.id,1,'Month');
	Opportunity[] ClonedOpp2 = [select Name, StageName, CloseDate from Opportunity where Id =:NewOppId];
	//new opp should be created with correct name
	System.assertEquals(opp1.CloseDate.addMonths(1),ClonedOpp2[0].CloseDate);
	//system.debug(ClonedOpp2[0].Name);
	
	}

}